package decorations
{
	import org.flixel.FlxPoint;
	
	/**
	 * ...
	 * @author JAC
	 */
	public class Torch extends Decoration
	{
		public static const GROW:uint = 0;
		public static const SHRINK:uint = 1;
		
		private var _redLight:Light;
		
		public function Torch(i:uint = 0, j:uint = 0)
		{
			super(i, j);
			
			loadGraphic(Assets.ImgDecorationTorch);
			
			_redLight = new Light(0, 0, this);
			_redLight.color = 0xFFAA0000;
			
			state = GROW;
		}
		
		override public function update():void
		{
			super.update();
			
			if (state == GROW)
			{
				if (_light.scale.x >= 1.5)
				{
					state = SHRINK;
					return;
				}
				else
				{
					if (_timer.hasExpired)
					{
						_light.scale.x += 0.5;
						_light.scale.y += 0.5;
						_redLight.scale.x += 0.5;
						_redLight.scale.y += 0.5;
						_timer.reset(1000);
					}
				}
			}
			else
			{
				if (_light.scale.x <= 1)
				{
					state = GROW;
					return;
				}
				else
				{
					if (_timer.hasExpired)
					{
						_light.scale.x -= 0.5;
						_light.scale.y -= 0.5;
						_redLight.scale.x -= 0.5;
						_redLight.scale.y -= 0.5;
						_timer.reset(1000);
					}
				}
			}
		}
		
		public static function addTorchesAroundExits():void
		{
			var exits:Array = Maze.exits;
			
			for (var k:uint = 0; k < exits.length; k++)
			{
				var exit:FlxPoint = exits[k];
				var exitTile:FlxPoint = Maze.getTileByPoint(exit);
				if (exitTile.x == 0)
				{
					Registry.decorations.add(new Torch(0, exitTile.y - 1));
					Registry.decorations.add(new Torch(0, exitTile.y + 1));
				}
				else if (exitTile.x == Maze.widthInTiles - 1)
				{
					Registry.decorations.add(new Torch(Maze.widthInTiles - 1, exitTile.y - 1));
					Registry.decorations.add(new Torch(Maze.widthInTiles - 1, exitTile.y + 1));
				}
				else if (exitTile.y == 0)
				{
					Registry.decorations.add(new Torch(exitTile.x - 1, 0));
					Registry.decorations.add(new Torch(exitTile.x + 1, 0));
				}
				else
				{
					Registry.decorations.add(new Torch(exitTile.x - 1, Maze.heightInTiles - 1));
					Registry.decorations.add(new Torch(exitTile.x + 1, Maze.heightInTiles - 1));
				}
			}
		}
	}
}